<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Json</title>
</head>
<body>

</body>
<script>
    /*
        Json:字符串数据格式
            key:value形式
        第一种：
            {"id":1,"username":"貂蝉","age":18}
        第二种：
            [
                {"id":1,"username":"貂蝉","age":18},
                {"id":2,"username":"吕布","age":30}
            ]

        切记注意：
            注意json数据类型:字符串和JSON对象
     */
    //Json格式的字符串数据
    let user = '{"id":1,"name":"李四","age":22}';
    //将user字符串转成Josn对象
    let json = JSON.parse(user);
    // alert(json.name);

    let userList = '[{"id":1,"name":"李四","age":22},{"id":2,"name":"张三","age":23}]';
    let jsonList = JSON.parse(userList);
    alert(jsonList[0].name);
    alert(jsonList[1].age);
</script>
</html>